package scanner.impl;

import isgooddata.IsGoodData;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import pojo.Customer;
import scanner.DataScanner;

public class DataScannerImpl implements DataScanner {
	private InputStream in;
	private Scanner scaner;
	
	public DataScannerImpl(InputStream in) {
		super();
		this.in = in;
		scaner=new Scanner(in);
		
	}

	public List<Customer> scann() {
		List<String> list=preScan();
		List<Customer> list1=new ArrayList<Customer>();
		String reg="\\s+";
		for(String s:list){
			String[] ss=s.split(reg);
			if(IsGoodData.isGoodData(ss)){
				Customer c=new Customer();
				c.setId((ss[0]));
				c.setName(ss[1]);
				c.setEmail(ss[2]);
				c.setSex(ss[3]);
				c.setBirthday(ss[4]);
				list1.add(c);
			}
		}
		return list1;
	}
	
	private List<String> preScan(){
		List<String> list=new ArrayList<String>();
		while(scaner.hasNext()){
			list.add(scaner.nextLine());
		}
		return list;
	}
	
	
	

}
